<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
<script src="/js/layui/layui.js"></script>
<style type="text/css">
    .layui-form-label {
        width: 100px;
    }
</style>
<body>
<div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="selFilter">
                        <div class="layui-form-item">
                            <label class="layui-form-label">授权开始时间：</label>
                            <div class="layui-input-block">
                                <input style="width: 200px;" type="text" name="depName" id="starttime"
                                       placeholder="" class="layui-input" lay-verify="required">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">授权结束时间：</label>
                            <div class="layui-input-block">
                                <input style="width: 200px;" type="text" name="depName" id="endtime"
                                       class="layui-input" lay-verify="required">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn layui-btn-sm layui-icon layui-icon-add-1" id="addbtn" lay-submit lay-filter="formDemo">
                                    授权
                                </button>
                                <button class="layui-btn layui-btn-sm layui-icon layui-icon-close" id="back">
                                    取消
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
    </div>
</div>
<script type="text/javascript">
    layui.use(['laydate','form'], function () {
        var $ = layui.$;
        var laydate = layui.laydate
        var form=layui.form;
        var banquanId=layui.data("banquan").getdata.copyrightid;//得到版权id
        var stationId=layui.data("banquan_stationId").getdata.station_id;//得到stationId
        //日期时间选择器
        laydate.render({
            elem: '#starttime'
            , type: 'datetime'
        })
        laydate.render({
            elem: '#endtime'
            , type: 'datetime'
        })
    form.on('submit(formDemo)', function () {
        if ($("#endtime").val() <= $("#starttime").val()) {
            layer.msg("结束时间错误")
            return false;
        }
        $.ajax({
            method: "get",
            url: "/admin/copyrightstation/addCopyRight",
            data: {
                stationid:stationId,
                copyrightId:banquanId,
                beginTime: $("#starttime").val(),
                endTime: $("#endtime").val()
            },
            success: function (res) {
                if (res.code == 200) {
                    layer.msg('授权成功', {
                        icon: 1
                    });
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);    //关闭弹出层
                    }, 2000);
                    return;
                }
                    layer.msg('授权失败', {
                        icon: 2
                    });
            },
            error: function (res) {
                layer.msg('服务器异常或网络原因', {
                    icon: 2
                });
            }
        });
        return false;
    });
        $('#back').click(function () {
            var index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            parent.layer.close(index)    //关闭弹出层
        })
    });
</script>
</body>
</html>
